package com.webdemo11.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.webdemo11.pojo.User;

public class UserDao {
	private SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	public void addUser(User user) {
		sessionFactory.getCurrentSession().save(user);
	}
	public void deleteUser(User user) {
		sessionFactory.getCurrentSession().delete(user);
	}
	public void updateUser(User user) {
		sessionFactory.getCurrentSession().update(user);
	}
	public User getUser(int id) {
		User user = (User)sessionFactory.getCurrentSession().get(User.class, id);
		return user;
	}
	@SuppressWarnings("unchecked")
	public List<User> getUsers() {
		String hql="from User";
		List<User> users = sessionFactory.getCurrentSession().createQuery(hql).list();
		return users;
	}
}
